import os

all_size = 0


def dir_size(dir_name):
    global all_size
    file_list = os.listdir(dir_name)  # 获取目录内的文件列表
    print(file_list)
    for file in file_list:
        file_path = os.path.join(dir_name, file)
        print(dir_name)
        if os.path.isfile(file_path):  # 如果是文件
            size = os.path.getsize(file_path)
            print(size)
            all_size += size          # 没有++ --
            # all_size = all_size + size
            print(file_path)
        else:
            # os.path.isdir(file_path)  # 如果是目录
            dir_size(file_path)       # 递归调用
           # all_size += dir_size(file_path)


print('-' * 50)
print('目录文件如下：')
print('-' * 50)
dir_size('/Program Files/Pycvirtual/Phyton-doc/handler')
print('-' * 50)
print('目录总大小：', all_size, '字节')
print('-' * 50)
